package helper.stringHelper;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;

public class StringHelper {
	public static String readFile(String path) throws IOException{

		String buffer, result;
		buffer="";
		result="";

		FileReader fr = new FileReader(path);
		BufferedReader br = new BufferedReader(fr);

		while ((buffer = br.readLine()) != null) {
			result = result + buffer+"\n";
		}

		return result;
	}


	public static String readStream(Reader reader) throws IOException{
		String buffer, result;
		buffer="";
		result="";
		BufferedReader br = new BufferedReader(reader);

		while ((buffer = br.readLine()) != null) {
			result = result + buffer+"\n";
		}

		return result;

	}
	
	public static String[] getStringArray(HashMap input){
		Object o = input.values().toArray()[0];
		Object[] values; 
		if (o instanceof ArrayList)
			values = ((ArrayList) o ).toArray();
		else if (o == null) 
			values = new Object[]{};
		else 
			values = new Object[]{o.toString()};
		
		String[] response = new String[values.length]; 
		
		
		
		
		for (int i=0; i<values.length; i++)
			response[i] = values[i].toString();

		return response;
	}

}
